//
//  AddViewController.m
//  TodoDemo
//
//  Created by Tank on 16/2/21.
//  Copyright © 2016年 qtone. All rights reserved.
//

#import "AddViewController.h"

@interface AddViewController() <UITextViewDelegate>

@property (weak, nonatomic) IBOutlet UILabel *tipLbl;
@property (weak, nonatomic) IBOutlet UITextView *textview;
@property (weak, nonatomic) IBOutlet UIButton *saveBtn;

@end

@implementation AddViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (IBAction)saveAction:(id)sender {
    NSString *content = _textview.text;
    NSCharacterSet *whitespace = [NSCharacterSet whitespaceAndNewlineCharacterSet];
    content = [content stringByTrimmingCharactersInSet:whitespace];
    if (content.length > 0) {
        [self.delegate addTodoData:content];
        [self.navigationController popViewControllerAnimated:YES];
    } else {
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"警告" message:@"待办事项不能为空!" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *doneAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [self dismissViewControllerAnimated:YES completion:nil];
        }];
        [alertController addAction:doneAction];
        [self presentViewController:alertController animated:YES completion:nil];
    }
}


#pragma mark - UITextViewDelegate

- (void)textViewDidChange:(UITextView *)textView {
    if (textView.text.length > 0) {
        _tipLbl.hidden = YES;
    } else {
        _tipLbl.hidden = NO;
    }
}

@end
